        
[section .text]

global	memcpy_asm
global	memset_asm
global  strcpy_asm



memcpy_asm:
	push	ebp
	mov	ebp, esp

	push	esi
	push	edi
	push	ecx

	mov	edi, [ebp + 8]	; Destination
	mov	esi, [ebp + 12]	; Source
	mov	ecx, [ebp + 16]	; Counter
.1:
	cmp	ecx, 0		
	jz	.2
        
	mov	al, [ds:esi]		
	inc	esi			

	mov	byte [es:edi], al	
	inc	edi			

	dec	ecx		
	jmp	.1		
.2:
	mov	eax, [ebp + 8]	

	pop	ecx
	pop	edi
	pop	esi
	mov	esp, ebp
	pop	ebp

	ret			


memset_asm:
	push	ebp
	mov	ebp, esp

	push	esi
	push	edi
	push	ecx

	mov	edi, [ebp + 8]	; Destination
	mov	edx, [ebp + 12]	; Char to be putted
	mov	ecx, [ebp + 16]	; Counter
.1:
	cmp	ecx, 0		
	jz	.2		

	mov	byte [edi], dl		
	inc	edi			

	dec	ecx		
	jmp	.1		
.2:

	pop	ecx
	pop	edi
	pop	esi
	mov	esp, ebp
	pop	ebp


        
strcpy_asm:
	push    ebp
	mov     ebp, esp

	mov     esi, [ebp + 12] ; Source
	mov     edi, [ebp + 8]  ; Destination

.1:
	mov     al, [esi]               
	inc     esi                     

        mov     byte [edi], al
	inc     edi                     

	cmp     al, 0
	jnz     .1              

	mov     eax, [ebp + 8]  

	pop     ebp
	ret
        

